<?php
//=======================================
//###################################
// Kayako Web Solutions
//
// Source Copyright 2001-2004 Kayako Infotech Ltd.
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
// $Author: vshoor $ ($Date: 2006/03/21 20:38:57 $)
// $RCSfile: upgrade.php,v $ : $Revision: 1.2 $ 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###################################
//=======================================

if (!defined("INSWIFT")) {
	trigger_error("Unable to process $PHP_SELF", E_USER_ERROR);
}

// Improved Flood Protection
if (in_array(MODULE_PARSER, $registeredmodules))
{
		$_SWIFT["query"]["create"]["floodhash"] = "CREATE TABLE ". TABLE_PREFIX ."floodhash (
																		floodhashid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																		dateline INT UNSIGNED NOT NULL DEFAULT '0',
																		emailhash VARCHAR(32) NOT NULL DEFAULT '',
																		subjecthash VARCHAR(32) NOT NULL DEFAULT '',
																		PRIMARY KEY (floodhashid),
																		KEY floodhash1 (emailhash, subjecthash),
																		KEY floodhash2 (dateline)
																	);";

		$_SWIFT["query"]["insert"]["cron"][] = "INSERT INTO `". TABLE_PREFIX ."cron` (`nextrun`, `lastrun`, `chour`, `cminute`, `cday`, `module`, `action`, `autorun`, `name`) VALUES ('". time() ."', '". time() ."', '0', '0', '-1', 'parser', 'cleanup', '1', 'parsercleanup');";
}

// Troubleshooter > Ticket Redirect
if (in_array(MODULE_TROUBLESHOOTER, $registeredmodules))
{
	$_SWIFT["query"]["alter"]["troubleshooter"][] = "ALTER TABLE `". TABLE_PREFIX ."troubleshootersteps` ADD (redirecttickets SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0', redirectdepartmentid INT UNSIGNED NOT NULL DEFAULT '0');";
}

// Advanced Search
if (in_array(MODULE_TICKETS, $registeredmodules))
{
		$_SWIFT["query"]["create"]["ticketfilters"] = "CREATE TABLE ". TABLE_PREFIX ."ticketfilters (
																		ticketfilterid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																		dateline INT UNSIGNED NOT NULL DEFAULT '0',
																		filtertype ENUM('public', 'private') NOT NULL DEFAULT 'public',
																		title VARCHAR(255) NOT NULL DEFAULT '',
																		staffid INT UNSIGNED NOT NULL DEFAULT '0',
																		filteroptions ENUM('all', 'any') NOT NULL DEFAULT 'all',
																		PRIMARY KEY (ticketfilterid),
																		KEY ticketfilters1 (filtertype, staffid)
																	);";

		$_SWIFT["query"]["create"]["ticketfilterfields"] = "CREATE TABLE ". TABLE_PREFIX ."ticketfilterfields (
																		ticketfilterfieldid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																		ticketfilterid INT UNSIGNED NOT NULL DEFAULT '0',
																		dateline INT UNSIGNED NOT NULL DEFAULT '0',
																		fieldtitle VARCHAR(255) NOT NULL DEFAULT '',
																		fieldoper INT UNSIGNED NOT NULL DEFAULT '0',
																		fieldvalue VARCHAR(255) NOT NULL DEFAULT '',
																		PRIMARY KEY (ticketfilterfieldid),
																		KEY ticketfilterfields (ticketfilterid)
																	);";

	$_SWIFT["query"]["alter"]["ticketsearches"][] = "ALTER TABLE `". TABLE_PREFIX ."ticketsearches` ADD (ticketfilterid INT UNSIGNED NOT NULL DEFAULT '0');";
	$_SWIFT["query"]["alter"]["tickets"][] = "ALTER TABLE `". TABLE_PREFIX ."tickets` ADD (escalatedtime INT UNSIGNED NOT NULL DEFAULT '0');";


}


upgrade_updateVersion("3.00.80");
?>